from random import *
import time

#modified bernstein hash
def mb(a):
    j=0
    h=0
    while j<25:
        #h=33*h^a[j]
        #n*33 is equal to (n<<5)+n
        h=((h<<5)+h)^a[j]
        j+=1
    return h

#shifted add xor hash
def sax(a):
    j=0
    h=0
    while j<25:
        h^=(h<<5)+(h>>2)+a[j]
        j+=1
    return h

#elf hash
def elf(a):
    h=0
    g=0
    j=0
    while j<25:
        h=(h<<4)+a[j]
        g=h&0xf0000000
        if g!=0:
            h^=g>>24
        h&=~g
        j+=1
    return h

#fnv hash - output too long
#def fnv(a):
#    h=2166136261
#    j=0
#    while j<25:
#        h=(h*16777619)^a[j]
#        j+=1
#    return h

#one at a time hash - output too long
#def oaat(a):
#    h=0
#    j=0
#    while j<25:
#        h+=a[j]
#        h+=(h<<10)
#        h^=(h>>6)
#        j+=1
#    h+=(h<<3)
#    h^=(h>>11)
#    h+=(h<<15)
#    return h

if __name__=="__main__":
    i=0
    p=range(0,25)
    while i<25:
        p[i]=randint(0,255)
        i=i+1
    while 1:
        time.sleep(5)
        b=time.clock()
        r=elf(p)
        a=time.clock()
        print r
        print "time taken for elf                %s" %(a-b)
        time.sleep(5)
        b=time.clock()
        r=sax(p)
        a=time.clock()
        print r
        print "time taken for shift add xor      %s" %(a-b)
        time.sleep(5)
        b=time.clock()
        r=mb(p)
        a=time.clock()
        print r
        print "time taken for modified bernstein %s" %(a-b)
        #time.sleep(5)
        #b=time.clock()
        #r=fnv(p)
        #a=time.clock()
        #print r
        #print "time taken for fnv                %s" %(a-b)
        #time.sleep(5)
        #b=time.clock()
        #r=oaat(p)
        #a=time.clock()
        #print r
        #print "time taken for one at a time      %s" %(a-b)
